<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="../inc/conn.asp"-->
<!--#include file="../inc/md5.asp"-->
<!--#include file="../common/admin.asp"-->
<%
id=request.QueryString("id")
cid=request.QueryString("cid")
search=request.QueryString("search")
if search="搜索" then
	key=request.QueryString("key")
	mark=request.QueryString("mark")
	if key<>"" then
		sqlsearch=" and (CategoryId like '%"&key&"%' or title like '%"&key&"%')"
	end if
	if mark<>"" then
		sqlsearch=sqlsearch+" and mark="&mark&""
	end if
end if

if cid<>"" then 
	sqlsearch=sqlsearch+" and parent_cid="&cid&""
	set rss=conn.execute("select parent_cid from auctions where cid="&cid)
	if not rss.eof then
	parent_cid=rss("parent_cid")
	end if
	set rss=nothing
end if

if id<>"" then 
	sqlsearch=sqlsearch+" and fid="&id&""
	set rss=conn.execute("select fid from auctions where id="&id)
	if not rss.eof then
	fid=rss("fid")
	end if
	set rss=nothing
end if

if sqlsearch="" then sqlsearch=" and fid=0"
'分页-------------------------------------------------------
set Rs=server.CreateObject("ADODB.RecordSet")
sql="select count(sortid) from (Select ROW_NUMBER() OVER (order by mark desc,sort asc,id asc ) as sortid,* From auctions) as TempTable where 1=1 "&sqlsearch&""
Pager_Pagesize=10 '每页记录数
Rs.open sql,conn,1,1
Pager_TotalRecord=Rs(0) '总记录数
Rs.close
Pager_PageCount=int((Pager_TotalRecord/Pager_Pagesize)+0.99999) '计算总页数
CurrentPage=Request("page") '当前页
'如果不为数字则直接设置页码为1
if isnumeric(CurrentPage)=False Or CurrentPage="" then
	CurrentPage=1
'如果当前页数大于总页数，则直接设置页码为1
elseif  Clng(CurrentPage)>Pager_PageCount then
	CurrentPage=1
end if
Fieldsname=" id,istop,fid,sort,mark,title,CategoryId,ParentCategoryId,CategoryName,sortid"
orderBy=" Order by sortid asc"
'拆分SQL语句，必须是select开头，有唯一标识的列
if instr("select",sql)<>-1 then
	if CurrentPage = 1 then
		sql = replace(sql,"select count(sortid)"," select  top " & Pager_Pagesize  & Fieldsname)
	else  
		sql = replace(sql,"select count(sortid)"," select  top " & Pager_Pagesize   & Fieldsname) & " and sortid >(select max(sortid) from (" & replace(sql,"select count(sortid)"," select  top " & Pager_Pagesize * (CurrentPage - 1)  & Fieldsname) & orderBy & ") AA)"
	end if
end if
sql = sql & orderBy
Rs.open sql,conn,1,1
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>main</title>
<link href="../css/style.css" rel="stylesheet" type="text/css"/>
</head>

<body>
<div class="main">
  <div class="main-title">雅虎分类:  &nbsp;&nbsp;
    <%
  if parent_cid<>"" then response.Write "<a href='?cid="&parent_cid&"'>上一级</a>"
  if fid<>"" then response.Write "<a href='?id="&fid&"'>上一级</a>"
  %></div>
  <div class="main-content">
  <table width="100%" border="0" cellspacing="1" cellpadding="3" class="tab">
  <tr>
    <td colspan="6" align="center">
    <form name="form" method="get" action="">
    <input name="key" type="text" id="key" value="<%=key%>" maxlength="50" />
    <select name="mark" id="mark">
      <option value="">全部</option>
      <option value="0" <%if mark="0" then response.Write " selected"%>>禁用</option>
      <option value="1" <%if mark="1" then response.Write " selected"%>>正常</option>
    </select>
    <input type="submit" name="search" value="搜索" />
    </form>
    </td>
    </tr>
    </table>
  <table width="100%" border="0" cellspacing="1" cellpadding="3" class="tab">
  <form action="" method="post">
  <tr>
    <td align="center" bgcolor="#FFFFFF"><strong>选择</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>ID</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>FID</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>雅虎名称</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>排序</strong></td>
    <td align="center" bgcolor="#FFFFFF">是否推荐</td>
    <td align="center" bgcolor="#FFFFFF"><strong>状态</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>CategoryId</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>名称</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>雅虎父ID</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>操作</strong></td>
    </tr>
    <%do while not Rs.eof%>
  <tr>
    <td align="center" bgcolor="#FFFFFF"><input type="checkbox" name="checkbox" id="checkbox" value="<%=rs("id")%>" /></td>
    <td align="center" bgcolor="#FFFFFF"><%=rs("id")%></td>
    <td align="center" bgcolor="#FFFFFF"><%=rs("fid")%></td>
    <td bgcolor="#FFFFFF" title="<%=rs("CategoryName")%>">  <a href='?id=<%=rs("id")%>'><%=rs("CategoryName")%></a>
    </td>
    <td align="center" bgcolor="#FFFFFF"><%=rs("sort")%></td>
    <td align="center" bgcolor="#FFFFFF"><%if rs("istop")=0 then response.Write "否" else response.Write "<font color='red'>是</font>"%></td>
    <td align="center" bgcolor="#FFFFFF"><%if rs("mark")=true then response.Write "正常" else response.Write "<font color='red'>禁用</font>"%></td>
    <td align="center" bgcolor="#FFFFFF"><%=rs("CategoryId")%></td>
    <td bgcolor="#FFFFFF" title="<%=rs("title")%>"><%=rs("title")%>
      
    </td>
    <td align="center" bgcolor="#FFFFFF"><%=rs("ParentCategoryId")%></td>
    <td align="center" bgcolor="#FFFFFF"><a href="edit.asp?id=<%=rs("id")%>">修改</a></td>
    </tr>
    <%
	Rs.movenext
	loop
	Rs.close
	Set Rs=nothing
	%>
    <tr>
      <td colspan="11" align="center" bgcolor="#FFFFFF" class="page">
<input type="submit" name="button" id="button" value="删除" />
<input type="submit" name="button" id="button" value="禁用" /> 
      <input type="submit" name="button" id="button" value="正常" />
      <input type="submit" name="button" id="button" value="推荐" />
      <input type="submit" name="button" id="button" value="取消推荐" />
      </td>
    </tr>
    </form>
    <tr>
    <td colspan="11" align="center" bgcolor="#FFFFFF" class="page">　
      <%
	siteurl=request.servervariables("document_name")
	%>
    <form action="<%=siteurl%>" method="get">
    共 <%=Pager_TotalRecord%> 条 第<%=CurrentPage%>页 / 共 <%=Pager_PageCount%> 页
		<%
		pageurl="cid="&cid&"&id="&id&"&key="&key&"&mark="&mark&"&search="&search&"&"
		if CurrentPage=1 then
			response.Write(" 首页 ")
			response.Write(" 上一页 ")
		else
			response.Write(" <a href='"&siteurl&"?"&pageurl&"page=1'>首页</a> ")
			response.Write(" <a href='"&siteurl&"?"&pageurl&"page="& (CurrentPage-1) &"'>上一页</a> ")
		end if
		%>
		<%
		if Clng(CurrentPage)=Clng(Pager_PageCount) then
			response.Write(" 下一页 ")
			response.Write(" 尾页 ")
		else
			response.Write(" <a href='"&siteurl&"?"&pageurl&"page="& (CurrentPage+1) &"'>下一页</a> ")
			response.Write(" <a href='"&siteurl&"?"&pageurl&"page="& Pager_PageCount &"'>尾页</a> ")
		end if
		%>
		&nbsp;
		<input name="page" type="text" value="<%=CurrentPage%>" size="1" maxlength="10" />
        <input type="submit" name="button" value="跳转" />
        <input type="hidden" name="cid" value="<%=cid%>" />
        <input type="hidden" name="id" value="<%=id%>" />
        <input type="hidden" name="key" value="<%=key%>" />
        <input type="hidden" name="mark" value="<%=mark%>" />
        <input type="hidden" name="search" value="搜索" />
        </form>
      </td>
    </tr>
  </table>
</div>
</div>
</body>
</html>
<%
checkbox=request.Form("checkbox")
if checkbox<>"" then	
	if request.Form("button")="删除" then
		conn.execute("delete from auctions where id in (SELECT id FROM dbo.auctions AS auctions WHERE (fid IN (SELECT id FROM dbo.auctions AS auctions WHERE (fid IN (SELECT id FROM dbo.auctions AS auctions WHERE (fid IN (SELECT id FROM dbo.auctions AS auctions WHERE (fid in ("&checkbox&")))))))))")
		conn.execute("delete from auctions where id in (SELECT id FROM dbo.auctions AS auctions WHERE (fid IN (SELECT id FROM dbo.auctions AS auctions WHERE (fid IN (SELECT id FROM dbo.auctions AS auctions WHERE (fid in ("&checkbox&")))))))")
		conn.execute("delete from auctions where id in (SELECT id FROM dbo.auctions WHERE (fid IN (SELECT id FROM dbo.auctions AS auctions WHERE (fid in ("&checkbox&")))))")
		conn.execute("delete from auctions where fid in ("&checkbox&")")
		conn.execute("delete from auctions where id in("&checkbox&")")
	
	elseif request.Form("button")="禁用" then
	    conn.execute("update auctions set mark=0 where id in (SELECT id FROM dbo.auctions AS auctions WHERE (fid IN (SELECT id FROM dbo.auctions AS auctions WHERE (fid IN (SELECT id FROM dbo.auctions AS auctions WHERE (fid IN (SELECT id FROM dbo.auctions AS auctions WHERE (fid in ("&checkbox&")))))))))")
		conn.execute("update auctions set mark=0 where id in (SELECT id FROM dbo.auctions AS auctions WHERE (fid IN (SELECT id FROM dbo.auctions AS auctions WHERE (fid IN (SELECT id FROM dbo.auctions AS auctions WHERE (fid in ("&checkbox&")))))))")
		conn.execute("update auctions set mark=0 where id in (SELECT id FROM dbo.auctions WHERE (fid IN (SELECT id FROM dbo.auctions AS auctions WHERE (fid in ("&checkbox&")))))")
		conn.execute("update auctions set mark=0 where fid in ("&checkbox&")")
		conn.execute("update auctions set mark=0 where id in ("&checkbox&")")
		
	elseif request.Form("button")="正常" then
		conn.execute("update auctions set mark=1 where id in (SELECT id FROM dbo.auctions AS auctions WHERE (fid IN (SELECT id FROM dbo.auctions AS auctions WHERE (fid IN (SELECT id FROM dbo.auctions AS auctions WHERE (fid IN (SELECT id FROM dbo.auctions AS auctions WHERE (fid in ("&checkbox&")))))))))")
		conn.execute("update auctions set mark=1 where id in (SELECT id FROM dbo.auctions AS auctions WHERE (fid IN (SELECT id FROM dbo.auctions AS auctions WHERE (fid IN (SELECT id FROM dbo.auctions AS auctions WHERE (fid in ("&checkbox&")))))))")
		conn.execute("update auctions set mark=1 where id in (SELECT id FROM dbo.auctions WHERE (fid IN (SELECT id FROM dbo.auctions AS auctions WHERE (fid in ("&checkbox&")))))")
		conn.execute("update auctions set mark=1 where fid in ("&checkbox&")")
		conn.execute("update auctions set mark=1 where id in ("&checkbox&")")
	
	elseif request.Form("button")="推荐" then
	    conn.execute("update auctions set istop=1 where id in ("&checkbox&")")
	
	elseif request.Form("button")="取消推荐" then
	    conn.execute("update auctions set istop=0 where id in ("&checkbox&")")
	end if
	response.Redirect "type.asp?page="&request.QueryString("page")&""
end if
%>